#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
  int maxDistance(vector<vector<int>> &arrays)
  {
    int ta, tb;
    int n = arrays.size();
    ta = arrays[0].back();
    tb = arrays[0][0];
    int ans = 0;
    for (int i = 1; i < n; i++)
    {
      ans = max({ans, abs(arrays[i][0] - ta), abs(arrays[i].back() - tb)});
      ta = max(ta, arrays[i].back());
      tb = min(tb, arrays[i][0]);
    }
    return ans;
  }
};
int main()
{
  Solution s;

  return 0;
}
